<!---------------------------------------
	send auto response email(all pass)
---------------------------------------->

<?php
$purpose = $_POST['purpose']; 
$fname = $_POST['fname'];    
$evalue = $_POST['evalue']; 
$ea = $_POST['ea']; 

if($ea=="none")
	$warningmsg=" ";
else
	$warningmsg="Based on details provided, the estimate loan amount is around ".$ea;   
//echo $purpose;
//echo $fname;
//echo $evalue;

//send email thru server
/*$to = "benimaru_x_6@hotmail.com";
$subject = "testing";

$emailtmp='aptest.htm';
$fp = fopen($emailtmp, "r");
$read= fread($fp, filesize($emailtmp));	
$read= str_replace("-Name-", $fname, $read);
fclose($fp);
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= "Content-Type:text/html;charset=\"utf-8\"\r\n";
$header .= "From:   ".$from."\r\n";
$header .= "BCC: cashlogin1@gmail.com \r\n";
mail($to,$subject,stripslashes($read),$header); */


//send sms
require("../sms/smsconn.php");
//$monumber="0435215805";
$monumber="";
$messcontent="ajax testing 9:37";

$si = new SmsInterface();
$si->addMessage($monumber,$messcontent);
	
if (!$si->connect($username,$password,true,false)){
	echo "failed. Could not contact sms server.\n";
}
elseif (!$si->sendMessages()) {
	echo "failed. Could not send message to server.\n";
	if ($si->getResponseMessage() !== NULL)
		echo "<br/>Reason: " . $si->getResponseMessage() . "\n";
} 


//vision6 email API
require_once("../automail/mailapi_header.php");
$email="MFtesting1234@hotmail.com";
$new_contacts = array (array('Email' => $email,  'FIRST NAME' => $fname),);

    /* ________________________________________________ */
    /* **** addContacts and searchContacts Example **** */

    /*
     * Contacts can now be added to the new Database
     * :NOTE: addContacts does not trigger any event emails,
     *   whereas subscribeContact does (but can only add 1 at a time)
     */
    if ($database_id) {
        print CRLF . 'Adding Contacts...' . CRLF;

        $response = getResponse($enc, request($ch, $enc->request('addContacts', array($database_id, $new_contacts))));

        if (is_array($response) && count($response) > 0) {
            /*
             * Align the returned Contact IDs with the existing array
             */
            foreach ($response as $idx => $id) {
                $new_contacts[$idx]['id'] = $id;
            }

            /*
             * Store the Contact IDs returned for later (when they are used as Campaign recipients)
             */
            $send_array = $response;
            print 'New Contacts added (total ' . count($send_array) . ')' . CRLF;
        } else {
            print 'Contacts could not be created' . CRLF;
        }
    }
	
//edit email 
		$emailtmp = "auto_response_email.html";
		$fp = fopen($emailtmp, "r");
		
		$read= fread($fp, filesize($emailtmp));
		
		$read= str_replace("-Name-", $fname, $read);
		$read= str_replace("-Purpose-", $purpose, $read);
		$read= str_replace("-estimat value-", $warningmsg, $read);
		//$read= str_replace("-Code-", $preappcode, $read);
		//$read= str_replace("-subjectInfo-", $subjectInfo, $read);
		$mailsubject=$fname.", all pass";

$email_content = array("email_name"=>"pre-approval auto reply","subject"=>$mailsubject,"type"=>"html","html_content"=>stripslashes($read),"from_name"=>"Morgan Finance","from_address"=>"application@morganfinance.com.au","reply-to_address"=>"application@morganfinance.com.au","postal_address"=>"","authorised_sender"=>"Elizabeth Taylor","unsubscribe_link"=>false,"edit_profile_link"=>false,);

$response = getResponse($enc, request($ch, $enc->request('addEmail', array($email_content))));	
  
        if ($response > 0) 
			print "Email succeed to add.";
		else
			print "Can not add email.";
			
		$email_id = $response;	
			
			
    /* _____________________________ */
    /* **** addCampaign Example **** */


    /* IMPORTANT: Ensure that the current database is correct, any added contacts are valid,
     *   and the email message selected is correct
     */
    if ($email_id && $database_id && is_array($send_array) && count($send_array) > 0) {
        /* Start a non-scheduled send in 10 minutes' time using the current database and email message
         *   (see the API documentation for more details)
         * :NOTE: 'non-scheduled' does not send a notification email to the user on completion of the send
         *
         * The following code really will send emails - be sure all the above data is correct before enabling!
         *
         *  // End this comment block here to activate the addCampaign Example*/

        print CRLF . 'Adding Campaign...' . CRLF;

        $db_population = array (
            'db_id' => $database_id,
            'type'  => 'contacts',
            'list'  => $send_array,     // from addContacts or searchContacts above
            'time'  => 'now',           // only applies where 'type' is set to 'database'
        );

        $response = getResponse($enc, request($ch, $enc->request('addCampaign', array($email_id, array($db_population), time()+10, false))));
        unset($db_population);

        if ($response) {
            $queue_id = $response;
            print 'Queue ID ' . $queue_id . ' created' . CRLF;
            $campaign_id = false;

            // After a Queue ID is returned, wait until a Campaign ID is obtained
            // (see the API documentation for more details)
            // Trying for about 10 seconds, though it should only take about 3 to 5

            for ($count = 0; $count < 3 && !$campaign_id; $count++) {
                sleep(3);
                $response = getResponse($enc, request($ch, $enc->request('getCampaignIdByQueueId', array($queue_id))));
                $campaign_id = $response;
            }

            if ($campaign_id) {
                print 'Campaign ID ' . $campaign_id . ' for Queue ID ' . $queue_id . ' created' . CRLF;
            } else {
                print 'Could not obtain a Campaign ID for Queue ID ' . $queue_id . ' in the given time' . CRLF;
            }
        } else {
            print 'Could not obtain a Queue ID - Campaign creation failed' . CRLF;
        }

        // Now the Campaign status etc could be retrieved via getCampaignStatus

          // Remove this comment end marker to activate the addCampaign Example

    }
require_once("../automail/mailapi_footer.php");



?>